#include "VSEntityActor.h"
#include "VSGraphicInclude.h"
#include "VSStream.h"
#include "VSSceneMap.h"
using namespace VSEngine2;

IMPLEMENT_RTTI_NoCreateFun(VSEntityActor,VSActor)
BEGIN_ADD_PROPERTY(VSEntityActor,VSActor)
//REGISTER_PROPERTY(m_fMaxVelocity,m_fMaxVelocity,VSProperty::F_SAVE_LOAD_CLONE | VSProperty::F_REFLECT_NAME);
// REGISTER_PROPERTY(m_LocalScale,Scale);
// REGISTER_PROPERTY(m_LocalRotate,Rotate);
END_ADD_PROPERTY
IMPLEMENT_INITIAL_NO_CLASS_FACTORY_BEGIN(VSEntityActor)
IMPLEMENT_INITIAL_NO_CLASS_FACTORY_END
VSEntityActor::VSEntityActor()
{

}
VSEntityActor::~VSEntityActor()
{

}
void VSEntityActor::AddActorNodeToNode(VSActor * pActor,VSNode * pNode)
{
	pActor->m_pSceneMap->DeleteActor(pActor);
	if (pActor->GetActorType() == AT_CAMERA)
	{		
		pNode->AddCamera((VSCamera *)pActor->GetActorNode());
		
	}
	else if (pActor->GetActorType() == AT_LIGHT)
	{
		pNode->AddLight((VSLight *)pActor->GetActorNode());
	}
	else
	{
		pNode->AddChild((VSNode*)pActor->GetActorNode());
	}
	pActor->m_pSceneMap = m_pSceneMap;
}
void VSEntityActor::AddChildActor(VSActor * pActor)
{
	if (pActor)
	{
		m_ChildActor.AddElement(pActor);
		VSNode * pNode = DynamicCast<VSNode>(m_pNode);
		AddActorNodeToNode(pActor,pNode);
	}

}
void VSEntityActor::DeleteChildActor(VSActor * pActor)
{
	for(unsigned int i = 0 ; i < m_ChildActor.GetNum() ; i++)
	{
		if (m_ChildActor[i] == pActor)
		{
			m_ChildActor.Erase(i);
			pActor->m_pSceneMap->DeleteActor(pActor);
			return ;
		}
	}
}
VSActor * VSEntityActor::GetChildActor(unsigned int uiActorIndex)
{
	if (uiActorIndex < m_ChildActor.GetNum())
	{
		return m_ChildActor[uiActorIndex];
	}
	return NULL;
}
void VSEntityActor::DeleteChildActor(unsigned int uiActorIndex)
{
	if (uiActorIndex < m_ChildActor.GetNum())
	{
		m_ChildActor.Erase(uiActorIndex);
		m_ChildActor[uiActorIndex]->m_pSceneMap->DeleteActor(m_ChildActor[uiActorIndex]);
	}
}